package com.结构型模型.H代理模式.JDK动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author zhangjiawen
 * @Date: 2022/6/6 10:46
 */
public class Test2 {


    public static void main(String[] args) {
        Host host=new Host();

        Object o = Proxy.newProxyInstance(host.getClass().getClassLoader(), host.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                say(method.getName());
                Object invoke = method.invoke(host, args);
                return invoke;
            }

            public void say(String msg) {
                System.out.println("hello:" + msg);


            }

        });
        Rent rent=(Rent)o;
        rent.rent();


    }



}
